//
//  MBaseViewController.m
//  zwyb
//
//  Created by 阔 李 on 16/11/3.
//  Copyright © 2016年 yxnzb. All rights reserved.
//

#import "MBaseViewController.h"

// 判断是否为iOS7
#define iOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)

@interface MBaseViewController ()

@end

@implementation MBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //  不让顶部nav占位 不透明处理
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
    // iOS7顶部屏幕适配
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
#endif


    
    self.view.backgroundColor=[UIColor whiteColor];
    
    [self initNavLeftBtn];
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
//    if (KIsiPhoneX) {
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_top"] forBarMetrics:UIBarMetricsDefault];
//    }else{
//       [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_3"] forBarMetrics:UIBarMetricsDefault];
//    }
    
    [self.navigationController.navigationBar setShadowImage:nil];
    self.navigationController.navigationBar.translucent = NO;
    
}

#pragma mark 初始化nav left
-(void)initNavLeftBtn{
    UIButton *leftBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame=CGRectMake(0, 0, screenScale(25), screenScale(25));
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"return"] forState:UIControlStateNormal];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"return"] forState:UIControlStateSelected];
    [leftBtn addTarget:self action:@selector(leftNavItemClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarBtn=[[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem=leftBarBtn;
}

-(void)leftNavItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 隐藏navleft
- (void)leftNavHide
{
    self.navigationItem.leftBarButtonItem.customView.hidden = YES;
}

#pragma mark 隐藏navright
- (void)rightNavHide
{
    self.navigationItem.rightBarButtonItem.customView.hidden=YES;
}
#pragma mark 复写title
-(void)setTitle:(NSString *)title{
    [super setTitle:title];
    
    UILabel *titlelabel=[[UILabel alloc]initWithFrame:CGRectZero];
    titlelabel.backgroundColor= [UIColor clearColor];
    titlelabel.text= title;
    titlelabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:(18)];
    titlelabel.textColor =[ZJCModel colorWithString:@"ffffff"];
    
    [titlelabel sizeToFit];
    self.navigationItem.titleView = titlelabel;
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
